<?php
	function getName($str){
		$n=strrpos($str,".");
		//echo 'n = '.$n;
		$l=strlen($str);
		$name=substr($str,0,$n);
		return $name;
	}
	function getExtension($str) {
         $i = strrpos($str,"."); // take number char until [.] at the end {olthoud have . infrom of one more it still ok} 
         if (!$i) { return "1"; }
         $l = strlen($str) - $i;
         $ext = substr($str,$i+1,$l-1);
         return $ext;
 	}
	function Resize($dir,$image,$newdir,$newimage,$rewidth,$reheight,$quality){	
	
			list($width,$height,$type)=getimagesize($dir.$image);
			/*---------------compare h w to be explicit----------------------*/
			if($width>=$height){
				$reheight=($rewidth*$height)/$width;
			}
			else{
				$rewidth=($reheight*$width)/$height;
			}
			/*----------------------------------------------------------------*/
			$image_type=($type==1?"gif":($type==2?"jpeg":($type==3?"png":($type==6?"bmp":false))));
			$create="imagecreatefrom".$image_type;
			
			//$out_put="image/".$image_type;
			
			if($image_type){
				$source=$create($dir.$image);
				//echo '$source = '.$source;
				//return;
				$resize=imagecreatetruecolor($rewidth,$reheight);
				
				imagecopyresampled($resize,$source,0,0,0,0,$rewidth,$reheight,$width,$height);
				imagejpeg($resize,$newdir.$newimage,$quality);
				
				//$out_put($resize,$newdir,$newimage,$quality);
				echo "it work";
				return true;
			}
			else{
				echo "not work";
				return false;
			}
		}
?>